import { HYEventStore } from 'hy-event-store'

import { getRankings } from '../service/api_music'

const rankingMap = { 0: 'newRanking', 1: 'hotRanking', 2: 'originRanking', 3: 'upRanking' }

const rankingStore = new HYEventStore({
	state: {
		newRanking: {}, // 0: 新歌
		hotRanking: {}, // 1: 热门
		originRanking: {}, // 2: 原创
		upRanking: {} // 3: 飙升
	},
	actions: {
		getRankingDataAction(ctx) {
			// 0: 新歌榜 1: 热门榜 2: 原创榜 3: 飙升榜
			// for (let i = 0; i < 4; i++) {
			//   getRankings(i).then(res => {
			//     const rankingName = rankingMap[i]
			//     ctx[rankingName] = res.playlist
			//   })
			// }

			// 飙升
			getRankings(19723756).then(res => {
				const rankingName = rankingMap[3]
				ctx[rankingName] = res.playlist
			})
			// 新歌
			getRankings(3779629).then(res => {
				const rankingName = rankingMap[0]
				ctx[rankingName] = res.playlist
			})
			// 原创
			getRankings(2884035).then(res => {
				const rankingName = rankingMap[2]
				ctx[rankingName] = res.playlist
			})
			// 热门
			getRankings(3778678).then(res => {
				const rankingName = rankingMap[1]
				ctx[rankingName] = res.playlist
			})
		}
	}
})

export { rankingStore, rankingMap }
